#ifndef __TIMER_MANAGER_H__
#define __TIMER_MANAGER_H__

#include <event2/event.h>

#include <functional>
#include <unordered_map>
#include <mutex>
#include <thread>
#include <map>
#include <ctime>


struct event_base;

class TimerManager {
public:
    TimerManager();
    ~TimerManager();

    // 启动定时器
    void startTimer(std::function<void(int)> callback, int seconds);
    void startTimer(std::function<void(int)> callback, int seconds, int run_count);

    // 停止定时器
    void stopTimer();

private:
    static void timerCallback(evutil_socket_t fd, short events, void* arg);
    void runEventLoop();

    struct event_base* base_;
    struct event* timer_;
    std::function<void(int)> callback_;
    int timer_seconds_;
    struct timespec start_time_;
    bool running_;
    std::thread eventThread_;
    int run_count_;
};

#endif